package com.css.fxfzysx.modules.vaomeFacilities.controller;

import com.css.fxfzysx.base.response.RestResponse;
import com.css.fxfzysx.modules.lifeline.param.LifelineFoundationLibraryParam;
import com.css.fxfzysx.modules.lifeline.param.MajorProjectsParam;
import com.css.fxfzysx.modules.lifeline.param.PageParam;
import com.css.fxfzysx.modules.vaomeFacilities.entity.CipHisDamageEntity;
import com.css.fxfzysx.modules.vaomeFacilities.param.UpdateMajorProjectsParam;
import com.css.fxfzysx.modules.vaomeFacilities.service.HeDamageService;
import com.css.fxfzysx.modules.vaomeFacilities.vo.MajorProjectAllVo;
import com.css.fxfzysx.modules.vaomeFacilities.vo.MajorProjectPageVo;
import com.css.fxfzysx.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.formula.functions.Odd;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;

/**
 * 重大工程历史震害数据
 */
@RestController
@RequestMapping("heDamage")
@Slf4j
public class HeDamageController {

    @Autowired
    private HeDamageService heDamageService;

    /**
     * 分页
     *
     * @param param
     * @param request
     * @return
     */
    @GetMapping("page")
    public RestResponse page(MajorProjectsParam param, HttpServletRequest request) {
        try {
            int page = Integer.parseInt(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int size = Integer.parseInt(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            HashMap<String, Object> map = heDamageService.page(param, page, size);
            return RestResponse.succeed(map);
        } catch (Exception e) {
            log.error("get page error:{}", e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    /**
     * 根据id查
     * @param id
     * @return
     */
    @GetMapping("getById")
    public RestResponse getById(String id){
        try {
            MajorProjectPageVo vo = heDamageService.getById(id);
            return RestResponse.succeed(vo);
        } catch (Exception e) {
            log.error("get getById error:{}", e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @GetMapping("deleteByIds")
    public RestResponse deleteById(String ids){
        try {
            heDamageService.deleteByIds(ids);
            return RestResponse.succeed("删除成功!");
        } catch (Exception e) {
            log.error("get deleteByIds error:{}", e.getMessage(), e);
            return RestResponse.fail("删除失败!");
        }
    }

    /**
     * 修改
     */
    @PostMapping("updateById")
    public RestResponse updateById(@RequestBody UpdateMajorProjectsParam param){
        try {
            heDamageService.updateById(param);
            return RestResponse.succeed("修改成功!");
        } catch (Exception e) {
            log.error("post updateById error:{}", e.getMessage(), e);
            return RestResponse.fail("修改失败!");
        }
    }

    /**
     * 查询全部数据(地图展示)
     * @return
     */
    @GetMapping("getByVersionId")
    public RestResponse getByVersionId(String versionId){
        try {
            List<MajorProjectAllVo> list = heDamageService.getByVersionId(versionId);
            return RestResponse.succeed(list);
        } catch (Exception e) {
            log.error("get getByVersionId error:{}", e.getMessage(), e);
            return RestResponse.fail("查询失败!");
        }

    }
}
